package com.guigu.netty.controller;

import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import com.guigu.netty.entity.LocationEntity;
import com.guigu.netty.service.KafkaSender;
import com.guigu.tms.result.R;
import com.guigu.tms.result.ResultCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName NettyController
 * @Description
 * @Author liao
 * @Date2021/11/16 14:23
 * @Version V1.0
 **/
@RestController
@Api(tags = "车辆轨迹服务")
@RequestMapping("netty")
@Slf4j
public class NettyController {


    @PostMapping(value = "/push")
    public R push(@RequestBody LocationEntity locationEntity) {
        String message = JSONUtil.toJsonStr(locationEntity);
        log.info("HTTP 方式推送位置信息：{}", message);
        KafkaSender.send(KafkaSender.MSG_TOPIC, message);
        return new R<>(ResultCode.SUCCESS_CODE,"发送成功!",true);
    }
}
